home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
dtk_demo.zip
/
DIR_ATTR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-12
|
3KB
|
122 lines
/* DIR_ATTR.C
* counts files matching a filename specification and
* a file attribute specification and displays
* the filenames and attributes in columns
* last mod.: 31-AUG-91
*/
#include <STDIO.H>
#include <STDLIB.H>
#include <STRING.H>
#include <CONIO.H>
#include <L_FILE.H>
#include <L_MISC.H>
#include <L_DIR.H>
char *usage = "Use: DIR_ATTR file_spec [attribute_spec]\n"
"file attributes: RHSVDA, ! = not, "
"e.g. DIR_ATTR K*.* AS!R\n";
/* the file attribute specification consists of a string
* of the form [str1][!str2] where str1 consists of one or more of
* 'R', 'H', 'S', 'V', 'D' and 'A', which are interpreted as:
* R = read only
* H = hidden
* S = system
* V = volume label
* D = directory
* A = archive
* the program ignores other letters;
* str1!str2 means: having one or more of the attributes
* in str1 and none of the attributes in str2;
* e.g. "D!H" means: all directories which are not hidden
* and "!HSVD" means: all files except those which are hidden,
* system, volume labels or directories;
* omitting the attribute specification gives all files
* except hidden and system files and volume names
*/
#define MAX_FILES 100
File files[MAX_FILES];
char attr[] = "RHSVDA";
char file_spec[81];
char attr_spec[81];
/* to avoid the limit on the number of files we
* dynamically allocate memory for the array of Files
*/
/*---------------------------*/
void main(int argc,char **argv)
{
int i, j, k, num, num1, num_lines, ch;
int count[6];
for ( i=0; i<6; i++ )
count[i] = 0;
if ( argc < 2 )
{
printf(usage);
return;
}
else
strcpy(file_spec,strupr(argv[1]));
if ( argc < 3 )
strcpy(attr_spec,"!HSV");
else
strcpy(attr_spec,strupr(argv[2]));
if ( ( num = num_matching_files(file_spec,attr_spec) ) == -1 )
printf("\nInvalid file attribute specification.\n");
else if ( !num )
printf("\nNo files.\n");
else if ( num > MAX_FILES )
printf("\nMore than %d files.\n",MAX_FILES);
if ( num <= 0 || num > MAX_FILES )
return;
num1 = 4*(((num-1)/4)+1);
printf("\nFiles %s with attributes %s: %d\n",
file_spec,(*attr_spec=='\0'?"\"\"":attr_spec),num);
read_directory(file_spec,attr_spec,files);
num_lines = num1/4;
for ( i=0; i<num1; i++ )
{
if ( !output_redirected() && i>0 && !(i%92) )
{
printf("--More--");
getch();
for ( j=0; j<8; j++ )
putchar('\b');
}
k = i/4 + num_lines*(i%4);
if ( k < num )
{
printf("%12s ",files[k].name);
for ( j=0; j<6; j++ )
{
ch = ( (files[k].attribute>>j) & 1 ? attr[j] : '.' );
if ( ch != '.' )
count[j]++;
putchar(ch);
}
putchar( (i+1)%4 ? ' ' : '\n' );
}
else
putchar('\n');
}
for ( j=0; j<6; j++ )
printf(" %c=%d ",attr[j],count[j]);
printf("\n");
}